<!--
 * @Author: 黄宇/Hyuishine
 * @Date: 2022-05-10 16:41:39
 * @LastEditors: 黄宇/Hyuishine
 * @LastEditTime: 2025-03-03 09:48:21
 * @Description: 
 * @Email: hyuishine@gmail.com
 * @Company: 3xData
 * @youWant: add you want
-->
<template>
  <view class="container_page">

    <!-- 顶部自定义导航栏 -->
    <action-bar :options="navOptions" />

    <!--//! 头部 header -->
    <view class="header">
      <view class="fixedPane">
        <view class="imgs"></view>
      </view>

      <!-- header 常用公告板 -->
      <view class="tab">
        <view v-for="(module, iindex) in headerModules" :key="iindex" @click="toPage(module.url)">
          <image :src="require(`../../static/home/${module.icon}.png`)" mode="widthFix" />
          <view style="font-size: 28rpx;"> {{ module.label }} </view>
        </view>
      </view>
    </view>

    <!-- //! 主体内容 -->
    <view class="main">
      <!-- 技术服务机构部分 -->
      <view class="part">
        <!-- 标题  -->
        <view class="title">
          <view class="titleLeft">技术服务机构</view>
          <view
            @click="toPage('../../pages_workTableChild/agency/index?serviceType=' + (activeTab.agency === '检测机构' ? '1' : '2'))">
            查看更多</view>
        </view>

        <view class="card">
          <!-- tab标题 -->
          <view class="tab">

            <!-- tabPane  -->
            <view :class="{ active: activeTab.agency === '检测机构' }" @click="changeActiveTab('1')">
              <image :src="baseImgUrl + '/home/icon_maintenanceAgency.png'" mode="widthFix" />
              <!--// todo tabContent 待区分 -->
              <view>
                <view>维护保养检测机构</view>
                <view>机构数量：{{ agencyList.total1 }}</view>
              </view>
            </view>

            <!-- tabPane  -->
            <view :class="{ active: activeTab.agency === '评估机构' }" @click="changeActiveTab('2')">
              <image :src="baseImgUrl + '/home/icon_evaluationAgency.png'" mode="widthFix" />

              <view>
                <view>消防安全评估机构</view>
                <view>机构数量：{{ agencyList.total2 }}</view>
              </view>
            </view>
          </view>

          <!-- 该板块 列表内容 -->
          <view class="content_part" v-for="list, index in infoJiShuList" :key="index" @click="toInfo(list)">
            <view>{{ list.name }}</view>
          </view>
        </view>
      </view>

      <!-- 技术服务项目部分 -->
      <view class="part">
        <!-- 标题  -->
        <view class="title">
          <view class="titleLeft">技术服务项目</view>
          <view @click="toPage('/pages/service/index?serviceType=' + (bctiveTab.project === '检测项目' ? '1' : '2'))">查看更多
          </view>
        </view>

        <view class="card">
          <!-- tab标题 -->
          <view class="tab">

            <!-- tabPane  -->
            <view :class="{ active: bctiveTab.project === '检测项目' }" @click="changeBctiveTab('1')">
              <image :src="baseImgUrl + '/home/icon_maintenanceProject.png'" mode="widthFix" />
              <view>
                <view>维护保养检测项目</view>
                <view>项目数量：{{ projectList.total1 }}</view>
              </view>
            </view>

            <!-- tabPane  -->
            <view :class="{ active: bctiveTab.project === '评估项目' }" @click="changeBctiveTab('2')">
              <image :src="baseImgUrl + '/home/icon_evaluationProject.png'" mode="widthFix" />
              <view>
                <view>消防安全评估项目</view>
                <view>项目数量：{{ projectList.total2 }}</view>
              </view>
            </view>
          </view>

          <!-- 该板块 列表内容 -->
          <view class="content_part" v-for="(item, index) in infoList" :key="index" @click="toInfo1(item)">
            <view>{{ item.name }}</view>
          </view>
        </view>
      </view>

      <!-- 技术服务项目部分 -->
      <view class="part">
        <!-- 标题  -->
        <view class="title" @click="toPage('/pages/exposure/index')">
          <view class="titleLeft">曝光台</view>
          <view>查看更多</view>
        </view>

        <view class="card">
          <!-- 该板块 列表内容 -->
          <view class="content_part redMarker" v-for="(dist, index) in exposure" :key="index"
            @click="toPage('/pages/exposure/index?agencyName=' + dist.agencyName)">
            <view>{{ dist.agencyName }}</view>
          </view>
        </view>
      </view>
    </view>

    <view class="footer">
      <view>主办单位：江西省消防救援总队</view>
      <view>技术支持：江西三叉数信息科技有限公司</view>
      <view>投诉（业务咨询）电话：0791-86558315</view>
      <view>技术服务电话：0792-8577387</view>
    </view>
  </view>
</template>
<script>
import { baseApiUrl, baseImgUrl } from '@/config.js';
import {
  get_userInfo,
} from '@/api/login.js'
export default {
  data() {
    return {
      baseImgUrl: baseImgUrl,
      navOptions: {
        style: 'background-color:#20b37b;',
        center: {
          title: "江西省社会消防技术服务信息管理系统"
        }
      },
      // 标头  快速链接模块
      headerModules: [
        { label: '通知公告', icon: 'icon_board', url: '/pages/homeModules/board/list' },
        { label: '法律法规', icon: 'icon_laws', url: '/pages/homeModules/laws/index' },
        { label: '资料下载', icon: 'icon_download', url: '/pages/homeModules/download/index' },
        { label: '技术标准', icon: 'icon_techStandard', url: '/pages/homeModules/techStandard/index' },
      ],
      // 活动中的板块
      // agency：机构
      // project：项目
      activeTab: {
        agency: '检测机构',
      },
      bctiveTab: {
        project: '检测项目',
      },
      // 曝光台列表数据
      exposure: [],
      // 技术服务项目列表数据
      infoList: [],
      infoListTotal: 0,
      // 技术服务机构列表数据
      infoJiShuList: [],
      infoJiShuTotal: 0,
      // 项目负责人列表
      leaderList: [],
      // 执业人员列表
      practitionersList: [],
      // 机构列表
      agencyList: {
        maintenance: [],
        total1: 0, // 维护保养
        assessment: [],
        total2: 0, // 安全评估
      },
      projectList: {
        maintenance: [],
        total1: 0, // 维护保养
        assessment: [],
        total2: 0, // 安全评估
      },
      // 服务类型
      serviceTypeList: [
        {
          text: '维护保养检测',
          value: '1'
        },
        {
          text: '消防安全评估',
          value: '2'
        }
      ]
    }
  },
  created() {
    // 获取曝光台列表数据
    this.getHomeList()
    // 获取信息列表
    this.getList1()
    this.getList2()
    // 获取技术服务机构
    this.getJishuList1()
    this.getJishuList2()
  },
  mounted() {
    let token = this.$store.state.login.userInfo?.token
    if (token) {

      get_userInfo((({ data }) => {
        let index = data.roles.findIndex(item => item == 'mechanism')
        if (index != '-1') {
          this.getSubmits()
        }
        let remark = data?.sysUser?.remark
        if (remark == null || remark == '未修改密码') {
          uni.reLaunch({
            url: "/pages/login/components/ResetPassword",
          });
        }
      }), token)
    }
  },
  methods: {
    getSubmits() {
      this.$store.dispatch('getSubmitApi').then(res => {
        this.$store.commit('saveAuditState', res.msg)
        // 状态分为0：待审核；1：不通过，2：已通过，3：未提交审核
        // 只有当状态为1，或者3时弹窗展示
        if (res.msg == '1' || res.msg == '3') {
          uni.showModal({
            title: '提示',
            content: '当前机构处于【未提交状态】，为了不影响执业，请尽快到【机构信息变更】页面的最底部进行提交操作',
            success: function (res) {
              if (res.confirm) {
                uni.navigateTo({
                  url: '/pages_workTableChild/organizeInforChange/index'
                })
              } else if (res.cancel) {
                console.log('用户点击取消');
              }
            }
          });
        }
      })
    },
    // 跳转到我的 页面
    toMyInfo() {
      this.$parent.curMenu = 3
    },

    // 跳转页面
    toPage(url) {
      uni.navigateTo({
        url: url
      })
    },

    // 获取曝光台列表数据
    getHomeList() {
      let data = {
        pageNo: 1,
        pageSize: 5
      }
      this.$store.dispatch('getExposureList', data).then(data => {
        if (data && data.code === 200) {
          this.exposure = data.data.items
        }
      })
    },

    // 获取项目列表（维护保养）
    getList1() {
      // this.getSubmits()
      let data = {
        pageNo: 1,
        pageSize: 5,
        serviceType: '1',
        state: '1'
      }
      this.$store.dispatch('getHomeTaskList', data).then(data => {
        if (data && data.code === 200) {
          this.projectList.maintenance = data.data.items
          this.projectList.total1 = data.data.total
          // 默认值
          this.infoList = this.projectList.maintenance
        }
      })
    },
    // 获取项目列表（安全评估）
    getList2() {
      let data = {
        pageNo: 1,
        pageSize: 5,
        serviceType: '2',
        state: '1'
      }
      this.$store.dispatch('getHomeTaskList', data).then(data => {
        if (data && data.code === 200) {
          this.projectList.assessment = data.data.items
          this.projectList.total2 = data.data.total
        }
      })
    },
    // 获取机构列表（维护保养）
    getJishuList1() {
      let data = {
        pageNo: 1,
        pageSize: 5,
        serviceType: '1'
      }
      this.$store.dispatch('getReviewedList', data).then(data => {
        if (data && data.code === 200) {
          this.agencyList.maintenance = data.data.items
          this.agencyList.total1 = data.data.total
          // 默认值
          this.infoJiShuList = this.agencyList.maintenance
        }
      })
    },
    // 获取机构列表（安全评估）
    getJishuList2() {
      let data = {
        pageNo: 1,
        pageSize: 5,
        serviceType: '2'
      }
      this.$store.dispatch('getReviewedList', data).then(data => {
        if (data && data.code === 200) {
          this.agencyList.assessment = data.data.items
          this.agencyList.total2 = data.data.total
        }
      })
    },

    changeActiveTab(e) {
      if (e == '1') {
        this.getJishuList1()
        this.activeTab.agency = '检测机构'
        this.infoJiShuList = this.agencyList.maintenance
      }
      else if (e == '2') {
        this.getJishuList2()
        this.activeTab.agency = '评估机构'
        this.infoJiShuList = this.agencyList.assessment
      }
    },
    // 切换技术服务项目tab项
    changeBctiveTab(e) {
      if (e == '1') {
        this.getList1()
        this.bctiveTab.project = '检测项目'
        this.infoList = this.projectList.maintenance
      }
      else if (e == '2') {
        this.getList2()
        this.bctiveTab.project = '评估项目'
        this.infoList = this.projectList.assessment
      }
    },

    toInfo(row) {
      uni.navigateTo({
        url: '../../pages_workTableChild/organizeInforChange/form?id=' + row.agencyId
      })
    },
    toInfo1(item) {
      uni.navigateTo({
        url: '../../pages_workTableChild/projectManage/homeProjectManage?id=' + item.projectId
      })
    }
  },
  computed: {
    // 用户头像链接
    avatarUrl() {
      const url = this.$store.state.login.userInfo.avatar
      // 图片为空，显示默认图片
      if (url == '') {
        return baseImgUrl + "/header.png"
      }
      if (url) {
        return baseApiUrl + url
      } else {
        return false
      }
    }
  }
}
</script>
<style lang="scss" scoped>
@import "./style.scss";
</style>